{template 'member','header'}
<script type="text/javascript" src="images/js/validator.js"></script>
<div id="main">
  {template 'order' , 'left'}
  <div id="right">
    <p id="position"> <strong>当前位置：</strong><a href="">首页</a><a href="{$MODULE[member][url]}">会员中心</a><a href="{$M[url]}">订单</a>在线下单</p>
    <form action="{$M[url]}order.php?action=confirm" method="post" name="myform" id ="myform">
    <input type="hidden" name="goodsid" value="{$goodsid}" />
    <input type="hidden" name="goodsname" value="{$goodsname}" />
    <input type="hidden" name="goodsurl" value="{$goodsurl}" />
    <input type="hidden" name="unit" value="{$unit}" />
    <input type="hidden" name="price" value="{$price}" />
    <input type="hidden" name="carriage" value="{$carriage}" />
    <input type="hidden" name="stock" value="{$stock}" />
    <input type="hidden" name="verify" value="{$verify}" />
    <input type="hidden" name="forward" value="{$forward}" />
    <input type="hidden" name="isnewdeliver" value="{if $delivers}0{else}1{/if}" />
    <table cellpadding="0" cellspacing="1" class="table_form">
      <caption>订单信息</caption>
	  <tr>
        <th width="15%">产品ID：</th>
        <td>{$goodsid}</td>       
      </tr>
	  <tr>
        <th>产品名称：</th>
        <td><a href="{$goodsurl}" target="_blank">{$goodsname}</a></td>       
      </tr>
{if $carriage}
	  <tr>
        <th>产品运费：</th>
        <td>￥{$carriage}元</td>       
      </tr>
{/if}
      <tr>
        <th>产品单价：</th>
        <td>￥{$price}元/{$unit}</td>       
      </tr>
{if $stock}
	  <tr>
        <th>库存：</th>
        <td>{$stock} {$unit}</td>       
      </tr>
	  <tr>
        <th><font color="red">*</font> 订购数量：</th>
        <td><input type="text" name="number" value="{$number}" size="6" require="true" datatype="range|number" max="{$stock}" msg="当前库存数量为{$stock}，请重新填写|请填写正确的数量" msgid="msg_number"/> {$unit}<span id="msg_number"></span></td>       
      </tr>
{else}
      <tr>
        <th><font color="red">*</font> 订购数量：</th>
        <td><input type="text" name="number" value="{$number}" size="6" require="true" datatype="number" msg="请填写正确的数量" msgid="msg_number"/> {$unit}<span id="msg_number"></span></td>       
      </tr>
{/if}
      <tr>
        <th>给卖家留言：</th>
        <td><textarea name="note" id="note" rows="4" cols="60"></textarea></td>       
      </tr>
    </table>
{if $delivers}
    <table cellpadding="0" cellspacing="1" class="table_list">
      <caption>确认您的收货地址</caption>
	  <tr>
        <th width="60">收货人</th>
        <th width="60">配送区域</th>
        <th width="90">电话</th>
        <th width="90">手机</th>
        <th>地址</th>
        <th width="50">邮编</th>
        <th width="80">操作</th>
	  </tr>
{loop $delivers $k $d}
 	  <tr>
        <td><input type="radio" name="deliverid" value="{$d[deliverid]}" {if $k==0}checked{/if} onclick="set_deliverid(this.value);"/></td>
        <td id="consignee_{$d[deliverid]}">{$d[consignee]}</td>
        <td>{$AREA[$d[areaid]][name]}<input type="hidden" name="areaid_{$d[deliverid]}" id="areaid_{$d[deliverid]}" value="{$d[areaid]}"><input type="hidden" name="areaname_{$d[deliverid]}" id="areaname_{$d[deliverid]}" value="{$AREA[$d[areaid]][name]}"></td>
        <td id="telephone_{$d[deliverid]}">{$d[telephone]}</td>
        <td id="mobile_{$d[deliverid]}">{$d[mobile]}</td>
        <td id="address_{$d[deliverid]}">{$d[address]}</td>
        <td id="postcode_{$d[deliverid]}">{$d[postcode]}</td>
	  </tr>
{/loop}
   </table>
{/if}
<table cellpadding="0" cellspacing="1" id="newdeliver" style="display:{if $delivers}none{/if}" class="table_form">
    <caption>{if $delivers}新增{/if}收货地址</caption>
	  <tr>
        <th width="15%"><font color="red">*</font> 配送区域：</th>
        <td>
            <input type="hidden" name="d[areaid]" id="areaid" value="{$areaid}">
	  {if $areaid}
			<span id="areaname" style="cursor:pointer;" onClick="this.style.display='none';$('#reselect_areaid').show();">{$AREA[$areaid][name]} <font color="red">点击重选</font></span>
			<span id="reselect_areaid" style="display:none;">
			<span id="load_areaid"></span> 
			<a href="javascript:areaid_reload();">重选</a>
			</span>
	  {else}
			<span id="load_areaid"></span>
			<a href="javascript:areaid_reload();">重选</a>
	  {/if}
        </td> 
      </tr>
      <tr>
        <th><font color="red">*</font> 收货人：</th>
        <td><input type="text" name="d[consignee]" id="consignee" value="{$consignee}" size="12" require="true" datatype="require" msg="请填写收货人"/></td>       
      </tr>
	  <tr>
        <th><font color="red">*</font> 电话：</th>
        <td><input type="text" name="d[telephone]" id="telephone" value="{$telephone}" size="20" require="true" datatype="custom" regexp="^[\d|\-|\+]{3,20}$"  msg="请填写正确的电话" msgid="telephone_notice"/> 格式：010-10000000-801 <span id="telephone_notice"></span></td>     
      </tr>
	  <tr>
        <th><font color="red">*</font> 手机：</th>
        <td><input type="text" name="d[mobile]" id="mobile" value="{$mobile}" size="20" require="true" datatype="mobile" msg="请填写正确的手机" msgid="mobile_notice"/> 格式：13800000000 <span id="mobile_notice"></span></td>       
      </tr>
	  <tr>
        <th><font color="red">*</font> 地址：</th>
        <td><input type="text" name="d[address]" id="address" value="{$address}" size="60" require="true" datatype="require" msg="填写正确的地址"/></td>       
      </tr>
      <tr>
        <th><font color="red">*</font> 邮编：</th>
        <td><input type="text" name="d[postcode]" id="postcode" value="{$postcode}" size="8" require="true" datatype="zip" msg="填写正确的邮编" msgid="postcode_notice"/> 格式：100000 <span id="postcode_notice"></span></td>       
      </tr>
</table>
{if $delivers}
	<div class="button_box" style="padding-left:10px"><input type="button" name="dosubmit" value="新增收货地址" style="width:100px" onclick="add_deliver();" />&nbsp;&nbsp;<input type="submit" name="dosubmit" value=" 下一步 " /></div>
{else}
	<div class="button_box" style="padding-left:120px"><input type="submit" name="dosubmit" value=" 下一步 " /></div>
{/if}
   </form>	
  </div>
</div>
<div class="clear"></div>
{template 'phpcms','footer'}
<script language="javascript" type="text/javascript">
$().ready(function() {
	  {if $delivers}
	  change_deliver('false');
	  set_deliverid(deliverid);
	  {/if}
	  $('form').checkForm(1);
});

var deliverid = '{$delivers[0][deliverid]}';
function set_deliverid(deliverid)
{
	$('#areaid').val($('#areaid_'+deliverid).val());
	$('#areaname').val($('#areaname_'+deliverid).val());
	$('#consignee').val($('#consignee_'+deliverid).html());
	$('#telephone').val($('#telephone_'+deliverid).html());
	$('#mobile').val($('#mobile_'+deliverid).html());
	$('#address').val($('#address_'+deliverid).html());
	$('#postcode').val($('#postcode_'+deliverid).html());
}

function add_deliver()
{
    $('#newdeliver').show();
    $('#isnewdeliver').val('1');
	change_deliver('true');
}

function change_deliver(val)
{
    $('#consignee').attr('require', val);
    $('#telephone').attr('require', val);
    $('#mobile').attr('require', val);
    $('#address').attr('require', val);
    $('#postcode').attr('require', val);
	$('form').checkForm(1);
}

function areaid_load(id)
{
	$.get("load.php", { field: 'areaid', id: id }, function(data){
		$('#load_areaid').append(data);
	});
}

function areaid_reload()
{
	$('#load_areaid').html('');
	areaid_load(0);
}
areaid_reload();
</script>